<script setup lang="ts">
import { ref, watch } from 'vue';

let time = ref<number>(5)
const props = defineProps([
  'codeFlag'
])

watch(() => props.codeFlag, (newVal) => {
  if (newVal) {
    const timer = setInterval(() => {
      time.value--
      if (time.value === 0) {
        $emit('sendFlag', false)
        clearInterval(timer)
      }
    }, 1000)
  }
},
{
  immediate: true
})
const $emit = defineEmits([
  'sendFlag'
])
</script>



<template>
  <div>
    <span>获取验证码{{time}}s</span>
  </div>
</template>



<style scoped lang="scss"></style>